﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Media;

namespace Dotway.WPF.Controls.Utilities
{
    public class NotifiedColor :  INotifyPropertyChanged
    {
        private byte a = 255;
        private byte r = 0;
        private byte g = 0;
        private byte b = 0;
        private Color color = Color.FromArgb(255, 0, 0, 0);


        public NotifiedColor()
        { }

        public NotifiedColor(Color color)
        {
            this.Color = color;
        }

        public NotifiedColor(byte r, byte g, byte b)
        {
            this.Color = Color.FromRgb(r, g, b);
        }

        public NotifiedColor(byte a, byte r, byte g, byte b)
        {
            this.Color = Color.FromArgb(a, r, g, b);
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion INotifyPropertyChanged

        public byte A
        {
            get { return a; }
            set
            {
                a = value;
                color.A = a;
                OnPropertyChanged("A");
                OnPropertyChanged("Color");
            }
        }

        public byte R 
        {
            get { return r; }
            set
            {
                r = value;
                color.R = r;
                OnPropertyChanged("R");
                OnPropertyChanged("Color");
            } 
        }

        public byte G 
        {
            get { return g; }
            set
            {
                g = value;
                color.G = g;
                OnPropertyChanged("G");
                OnPropertyChanged("Color");
            } 
        }

        public byte B 
        {
            get { return b; }
            set
            {
                b = value;
                color.B = b;
                OnPropertyChanged("B");
                OnPropertyChanged("Color");
            }
        }

        public Color Color 
        {
            get { return color; }
            set
            {
                color = value;
                a = color.A;
                r = color.R;
                g = color.G;
                b = color.B;
                OnPropertyChanged("A");
                OnPropertyChanged("R");
                OnPropertyChanged("G");
                OnPropertyChanged("B");
                OnPropertyChanged("Color");
            }
        }
    }
}
